package com.keke.myblogv1.common.result;

import lombok.Data;
import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {
    private static final long serialVersionUID = 3887996952977952221L;

    private int code;

    private String msg;

    private T data;

    public ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult(ResultEnums resultEnums, T data) {
        this.code = resultEnums.getCode();
        this.msg = resultEnums.getMsg();
        this.data = data;
    }

    public ResponseResult(ResultEnums resultEnums) {
        this.code = resultEnums.getCode();
        this.msg = resultEnums.getMsg();
    }

    public ResponseResult() {

    }

    public static <T> ResponseResult<T> success(T data) {
        return new ResponseResult<T>(ResultEnums.SUCCESS_200, data);
    }

    public static ResponseResult success() {
        return new ResponseResult(ResultEnums.SUCCESS_200);
    }

    public static ResponseResult success(String msg) {
        return new ResponseResult(ResultEnums.SUCCESS_200.getCode(), msg);
    }

    public static ResponseResult success(int code, String msg) {
        return new ResponseResult(code, msg);
    }

    public static <T> ResponseResult<T> success(int code, String msg, T data) {
        return new ResponseResult<T>(code, msg, data);
    }

    public static ResponseResult success(ResultEnums resultEnums) {
        return new ResponseResult(resultEnums);
    }

    public static <T> ResponseResult<T> error(T data) {
        return new ResponseResult<T>(ResultEnums.ERROR_400, data);
    }

    public static ResponseResult error() {
        return new ResponseResult(ResultEnums.ERROR_400);
    }

    public static ResponseResult error(String msg) {
        return new ResponseResult(ResultEnums.ERROR_400.getCode(), msg);
    }

    public static ResponseResult error(int code, String msg) {
        return new ResponseResult(code, msg);
    }

    public static <T> ResponseResult<T> error(int code, String msg, T data) {
        return new ResponseResult<T>(code, msg, data);
    }

    public static ResponseResult error(ResultEnums resultEnums){
        return new ResponseResult(resultEnums);
    }
}
